              package com.java.diagnostics.visualizer.parser.vgc.j9;
              
              import com.java.diagnostics.visualizer.impl.strings.StringPair;
              import com.java.diagnostics.visualizer.impl.strings.TextReplacer;
              import java.util.ArrayList;
              import java.util.List;
              import java.util.regex.Matcher;
              import java.util.regex.Pattern;
              
              public class J9XMLCleaner
              {
                private static final String SEMICOLON = ";";
                private static final String ARROW = " (arrow)";
                private static final String ARROW_WITH_BRACKETS = "[^-]->";
                private static final String TGC_GC = "GC";
                private static final String TGC_GC_WITH_BRACKETS = "<GC";
                private static final String TGC_CONCURRENT = "CONCURRENT";
                private static final String TGC_CONCURRENT_WITH_BRACKETS = "<CONCURRENT";
                private static final String TGC_ALLOC_TLH = "Alloc TLH";
                private static final String TGC_NON_TLH = "non-TLH";
                private static final String TGC_NON_TLH_WITH_BRACKETS = "<  non-TLH";
                private static final String TGC_ALLOC_TLH_WITH_BRACKETS = "<Alloc TLH";
                private static final String LESS_THAN_ZERO = "less than 0";
                private static final String LESS_THAN_ZERO_WITH_BRACKETS = "<0";
                private static final String AMPERSAND = "&";
                private static final String CLINIT = "clinit";
                private static final String CLINIT_WITH_BRACKETS = "<clinit>";
                private static final String INIT = "init";
                private static final String INIT_WITH_BRACKETS = "<init>";
                private static final String NULL = "null";
                private static final String NULL_WITH_BRACKETS = "<null>";
                private static final String END_AXXON_MESSAGE = "end-axxon-message";
                private static final String AXXON_MESSAGE_XML_CLOSE = "</axxon-message>";
                private static final String AXXON_MESSAGE = "axxon-message";
                private static final String AXXON_MESSAGE_XML_OPEN = "<axxon-message>";
                private static final String HTML_LINE_BREAK = "<br>";
                private static final String XHTML_LINE_BREAK = "<br/>";
                private static final String XML_VERSION_1_0 = "<?xml version=\"1.0\" ?>";
                protected static final String EMPTY_STRING = "";
                private boolean patternsInited = false;
                private Pattern pattern_ARROW_WITH_BRACKETS;
                private TextReplacer replacer = null;
              
                public J9XMLCleaner()
                {
                  if (!this.patternsInited)
                    initialisePatterns();
                }
              
                public String stripBadCharacters(String text)
                {
                  text = this.replacer.replaceText(text);
              
                  text = this.pattern_ARROW_WITH_BRACKETS.matcher(text).replaceAll(" (arrow)");
              
                  return text;
                }
              
                private void initialisePatterns() {
                  List pairList = new ArrayList();
              
                  pairList.add(new StringPair("<axxon-message>", "axxon-message"));
              
                  pairList.add(new StringPair("</axxon-message>", 
                    "end-axxon-message"));
                  pairList.add(new StringPair("<init>", "init"));
                  pairList.add(new StringPair("<null>", "null"));
                  pairList.add(new StringPair("<clinit>", "clinit"));
                  pairList.add(new StringPair("<0", 
                    "less than 0"));
                  pairList.add(new StringPair("<Alloc TLH", 
                    "Alloc TLH"));
                  pairList
                    .add(new StringPair("<  non-TLH", "non-TLH"));
                  pairList.add(new StringPair("<CONCURRENT", 
                    "CONCURRENT"));
                  pairList.add(new StringPair("<GC", "GC"));
                  pairList.add(new StringPair("<0", 
                    "axxon-message"));
                  pairList.add(new StringPair(";", ""));
                  pairList.add(new StringPair("<?xml version=\"1.0\" ?>", ""));
              
                  pairList.add(new StringPair("&", ""));
              
                  pairList.add(new StringPair("<br>", "<br/>"));
              
                  StringPair[] pairs = 
                    (StringPair[])pairList
                    .toArray(new StringPair[0]);
              
                  this.replacer = new TextReplacer(pairs);
              
                  this.pattern_ARROW_WITH_BRACKETS = 
                    Pattern.compile("[^-]->");
              
                  this.patternsInited = true;
                }
              }

